#include "endingpanel.h"

#include <QPainter>

EndingPanel::EndingPanel(bool isLord,bool isWin,QWidget *parent)
    : QWidget{parent}
{
    m_bk.load(":/images/images/gameover.png");
    setFixedSize(m_bk.size());

    m_title = new QLabel(this);
    if(isLord && isWin)
    {
        m_title->setPixmap(QPixmap(":/images/images/lord_win.png"));
    }
    else if(isLord && !isWin)
    {
        m_title->setPixmap(QPixmap(":/images/images/lord_fail.png"));
    }
    else if(!isLord && isWin)
    {
        m_title->setPixmap(QPixmap(":/images/images/farmer_win.png"));
    }
    else if(!isLord && !isWin)
    {
        m_title->setPixmap(QPixmap(":/images/images/farmer_fail.png"));
    }
    m_title->move(125,125);
    m_panel = new ScorePanel(this);
    m_panel->move(75,230);
    m_panel->setFixedSize(260,160);
    m_panel->setMyFontColor(ScorePanel::red);
    m_panel->setMyFontSize(18);

    m_btn = new QPushButton(this);
    m_btn->move(84,429);
    QString style = R"(
        QPushButton{border-image: url(:/images/images/button_normal.png)}
        QPushButton:hover{border-image: url(:/images/images/button_hover.png)}
        QPushButton:pressed{border-image: url(:/images/images/button_pressed.png)}
)";
    m_btn->setStyleSheet(style);
    m_btn->setFixedSize(231,48);
    connect(m_btn,&QPushButton::clicked,this,&EndingPanel::ContinueGame);

}

void EndingPanel::setPlayerScore(int left, int right, int me)
{
    m_panel->setScore(left, right, me);
}
void EndingPanel::paintEvent(QPaintEvent *event)
{
        Q_UNUSED(event);
    QPainter p(this);
    p.drawPixmap(rect(),m_bk);
}
